package com.zklh.book.system.view.render;

import com.zklh.book.system.view.OperationOption;
import com.zklh.book.system.view.ViewRenderer;

import java.util.List;
import java.util.Map;

/**
 * 用于渲染指令列表
 *
 * @author 坐看落花
 * @version 1.0
 * @date 2021/3/21 10:37
 */
public class OperationViewRenderer implements ViewRenderer {

    /**
     * 需要参数 operations 指令集合, 一个List<OperationOption>, 需要登录用户的角色 role
     * @param params
     */
    @Override
    public void render(Map<String, Object> params) {
        List<OperationOption> operations = (List<OperationOption>) params.get("operations");
        String role = (String) params.get("role");
        System.out.println("");
        System.out.println("指令列表(输入指令序号执行指令):");
        if (operations != null && operations.size() > 0) {
            int cnt = 0;
            for (OperationOption operation : operations) {
                cnt++;
                System.out.print(operation.getCode()+": " + operation.getDesc() +"(" + (operation.getRoles().contains(role) ? "可用" : "不可用") +")\t");
                // 5个指令换行
                if (cnt % 5 == 0) {
                    System.out.println();
                }
            }
        }
        System.out.println();

    }
}
